/*
 示例
 var businessOpportunitiesSelWin;
 function selBusinessOpportunitiesSel(){
 if(!businessOpportunitiesSelWin){
 businessOpportunitiesSelWin= new businessOpportunitiesSel({customersId:'可以传入客户id'});
 businessOpportunitiesSelWin.on('onSelectItem', function(data) {
 form.getForm().findField("businessOpportunitiesSelId").setValue(data.id);
 form.getForm().findField("businessOpportunitiesSelName").setValue(data.name);
 }, this);
 }
 businessOpportunitiesSelWin.show();
 }
 * */
Ext.define("businessOpportunitiesSel",{
    extend:'Ext.window.Window',
    customersId:null,
    width:600,
    height:500,
    title:'业务机会选择',
    initComponent: function() {
        var searchFlds = new Ext.util.MixedCollection();
        searchFlds.add('bussName', new Ext.form.TextField({
            name: 'bussName',
            fieldLabel: '业务名称',
            allowBlank:false
        }));
        this.grid = Ext.create('gridView', {
            remoteSort: true,
            checkboxSelectionModel:     false,
            dataAutoLoad : false,
            searchFlds: searchFlds,
            entityClassName : 'com.rover.crm.entity.BusinessOpportunities',
            queryUrl : 'businessOpportunitiesController/query.action',
            deleteUrl:null,
            recordPk: [ "id" ],
            tbar:[
                searchFlds.get('company'),
                {xtype:'button',text:'查询',id:'btn_Query',iconCls:'btn_edit',handler:function(){
                    Ext.getCmp("businessOpportunitiesSel").executeQuery();
                }}
            ],
            listeners : {
                itemdblclick : function(grid, rowindex, e) {
                    Ext.getCmp("businessOpportunitiesSel").selectItem();
                }
            }
        });
        if(this.customersId){
            this.grid.getStore().on('beforeload', function(store, options) {
                store.proxy.extraParams.customersId = this.customersId;
            }, this, true);
        }
        this.grid.load();
        this.id = "businessOpportunitiesSel";
        this.items = [this.grid];
        this.layout= 'fit';
        this.modal = true; // 是否为模态窗口
        this.resizable = false; // 是否可以改变窗口大小
        this.buttonAlign= 'center',
            this.buttons = [{
                iconCls : "btn-ok",
                text : "确定",
                scope : this,
                handler : this.selectItem
            }, {
                text : "取消",
                iconCls : "btn-cancel",
                handler : this.onWinHide,
                scope : this
            }];
        this.addEvents({// 加入自定义事件
            "onSelectItem" : true
        });
        this.callParent(arguments);
    },
    selectItem : function() {
        var sm = this.grid.getSelectionModel();
        var records = sm.getSelection();
        if (records.length <= 0) {
            Ext.Msg.alert('提示', "未选中记录！");
            return;
        }
        this.fireEvent('onSelectItem', records[0].raw);// 激发自定义事件
        this.hide();

    },
    onWinHide : function() {
        this.hide();
    }
});